#include <stdio.h>
#include <k4a/k4a.h>
#include <k4arecord/record.h>
#include <k4arecord/playback.h>
#include <iostream>
#include <stdlib.h>
#include <opencv2/core/core.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <k4a/k4a.hpp>
#include <cstdlib>

using namespace cv;
using namespace std;


int main() {

k4a::capture capture;
const uint32_t device_count = k4a::device::get_installed_count();//查看设备个数
if (device_count == 0)	
{
	printf("No K4A devices found\n");
	return 0;
}


//Kinect 4 Azure related initial parameters
    k4a_device_t device = NULL;

// Configure of devices
    k4a_device_configuration_t config = K4A_DEVICE_CONFIG_INIT_DISABLE_ALL;
    config.camera_fps = K4A_FRAMES_PER_SECOND_30;
    config.color_format = K4A_IMAGE_FORMAT_COLOR_BGRA32;
    config.color_resolution = K4A_COLOR_RESOLUTION_720P;
    config.depth_mode = K4A_DEPTH_MODE_NFOV_UNBINNED;
    config.synchronized_images_only = true;



// START CONNECT TO "Kinect 4 Azure"
    if (K4A_RESULT_SUCCEEDED != k4a_device_open(K4A_DEVICE_DEFAULT, &device)) {
        printf("Failed to open device\n");
        goto Exit;
    }

    k4a_calibration_t calibration;
    if (K4A_RESULT_SUCCEEDED !=
        k4a_device_get_calibration(device, config.depth_mode, config.color_resolution, &calibration)) {
        printf("Failed to get calibration\n");
        goto Exit;
    }

//get calibration
    k4a_calibration_t sensor_calibration;
    k4a_device_get_calibration(device, config.depth_mode, config.color_resolution, &sensor_calibration);
    // float *intrinsics_v;
    cout << "----------------------------------------------------------" << endl;
    cout << "cx" << sensor_calibration.color_camera_calibration.intrinsics.parameters.param.cx << endl;
    cout << "cy" << sensor_calibration.color_camera_calibration.intrinsics.parameters.param.cy << endl;
    cout << "fx" << sensor_calibration.color_camera_calibration.intrinsics.parameters.param.fx << endl;
    cout << "fy" << sensor_calibration.color_camera_calibration.intrinsics.parameters.param.fy << endl;
    cout << "k1" << sensor_calibration.color_camera_calibration.intrinsics.parameters.param.k1 << endl;
    cout << "k2" << sensor_calibration.color_camera_calibration.intrinsics.parameters.param.k2 << endl;
    cout << "k3" << sensor_calibration.color_camera_calibration.intrinsics.parameters.param.k3 << endl;
    cout << "p1" << sensor_calibration.color_camera_calibration.intrinsics.parameters.param.p1 << endl;
    cout << "p2" << sensor_calibration.color_camera_calibration.intrinsics.parameters.param.p2 << endl;
    cout << "codx" << sensor_calibration.color_camera_calibration.intrinsics.parameters.param.codx << endl;
    cout << "cody" << sensor_calibration.color_camera_calibration.intrinsics.parameters.param.cody << endl;
    cout << "metric_radius" << sensor_calibration.color_camera_calibration.intrinsics.parameters.param.metric_radius
         << endl;
    Exit:
    printf("\nExit: cleaning up...");
    if (device != NULL) {
        k4a_device_close(device);
    }
    printf("\nExit: all shut down!\n");


    return 0;
}

